<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="net.sf.jOpinionPoll.facade.ClienteFacade"%>
<%@page import="net.sf.jOpinionPoll.facade.UsuarioFacade"%>
<%@page import="org.acegisecurity.Authentication"%>
<%@page import="org.acegisecurity.context.SecurityContextHolder"%>
<%@page import="org.acegisecurity.GrantedAuthority"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    <%
    WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(config.getServletContext());
    ClienteFacade f = (ClienteFacade)ctx.getBean("clienteFacade");
    UsuarioFacade u = (UsuarioFacade)ctx.getBean("usuarioFacade");
    
    out.print("TOTAL ................: " + f.count() + "<br/>");
    out.print("Cliente ............: " + f.findByPk(39751).getNome() + ", " + f.findByPk(39751).getEndereco().getLogradouro() + "<br/>");
    out.print("Usuario ............: " + u.findFetchByPk("erico").getPapeis().iterator().next().getTipoDePapel() + "<br/>");
    
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    GrantedAuthority[] grantedAuthority = authentication.getAuthorities();
    
    out.print("Usuario do sistema<br/>");
    out.print("Logado .............: " + authentication.getName() + "<br/>");
    out.print("Permissoes .............: ");
    for (GrantedAuthority ga : grantedAuthority)
    	out.print(ga.getAuthority() + ", ");
    
    %>
</body>
</html>